<?php

if(in_array($_SERVER['SERVER_ADDR'], array( '127.0.0.1', '___173.255.245.72' )) || ( isset($_REQUEST['deb']) && $_REQUEST['deb'] = 'woycc' ))
	return array( '', '', $sitemid = isset($_REQUEST['sitemid']) ? $_REQUEST['sitemid'] : '1', $time = time(), md5("{$sitemid}ffs{$time}"), '[]', 0 );

$app_id		= '56bb3767e41e3d8eced22723c5149bcd';
$app_sec	= 'fb87ca158c818d3f70a28e9a51044df9';
$game_url	= 'http://apps.facebook.com/find_more_friends/';
$need_perms	= array( 'email' , 'publish_stream', 'friends_status' );

include_once dirname(__FILE__) . '/sdk/facebook.php';
$_fb = new Facebook(array(
	'appId'  => $app_id,
	'secret' => $app_sec,
));

$sitemid = $_fb->getUser();
if(is_null($sitemid)) {
	$_get = http_build_query($_GET);
	$login_url = $_fb->getLoginUrl(array(
		'req_perms'	=> implode(',', $need_perms),
		'next'		=> "{$game_url}?{$_get}",
		'cancel_url'	=> "{$game_url}?{$_get}&cmd=canceled",
	));

	echo <<<EOT
<script>top.location.replace("$login_url");</script>
正在引導您進入Facebook授權頁面, 請稍候...
EOT;
	exit;
}

$sreq			= $_fb->getSignedRequest();
$access_token	= $_fb->getAccessToken();

$request_ids = isset($_GET['request_ids']) ? explode(',', $_GET['request_ids']) : array();
$request_ids = json_encode($request_ids);

$time = time();
$key = md5("{$sitemid}ffs{$time}");
$is_install = ( isset($_REQUEST['install']) && $_REQUEST['install'] == '1' ) ? 1 : 0;

return array( $app_id, $access_token, $sitemid, $time, $key, $request_ids, $is_install );